import React from 'react';

import AnalysisTitle from 'components/AnalysisTitle';
import TopNavBar from 'components/TopNavBar';
// 业务组件
import Indicators from './components/Indicators'
import Statistics from './components/Statistics'
import Analysis from './components/Analysis'

import { standardSource, abstractList } from '../../../public/config/quality';

class Quality extends React.Component {
  constructor(props) {
    super(props);

    const abstractValue = ['TURBIDITY']
    let abstractOption = this.columnsList(abstractValue)
    this.state = {
      abstractValue,
      abstractOption,
    }
  }

  // 处理 columns
  columnsList = (value) => {
    let abstractOption;
    const list = abstractList;
    if(Array.isArray(list)){
      abstractOption = list.find(function(ele){
        if(ele['value'] === value.join('')) return ele;
      })
    }
    return abstractOption;
  }
  
  handleChange = (abstractValue) => {
    const abstractOption = this.columnsList(abstractValue);
    this.setState({
      abstractValue,
      abstractOption,
    })
  }

  render() {
    const { props, state } = this;
    const { route } = props;
    const { abstractValue, abstractOption } = state;

    let selectList = []
    abstractList.map(ele => { if(ele.flag === true) selectList.push(ele) });
    return (<>
      <TopNavBar title={route.title} />
      <Indicators
        standardSource={standardSource}
        abstractList={abstractList}
      />
      <AnalysisTitle />
      <Statistics
        defaultValue={abstractValue}
        defaultOption={abstractOption}
        abstractList={selectList}
        onChange={this.handleChange}
      />
      <Analysis
        defaultValue={abstractValue}
        defaultOption={abstractOption}
      />
    </>)
  }
}

export default Quality;